# sqlite数据库连接
import sqlite3

# 连接数据库
conn = sqlite3.connect("book.db")

# 创建游标
cursor = conn.cursor()

# 建表
sql = '''create table if not exists sys_user(
id int(11) primary key,
name varchar(20) not null,
age int(3) not null
          )'''

cursor.execute(sql)
conn.commit()  # 提交事务

# 插入数据
# insert_sql = "insert into sys_user(id,name,age) values (?,?,?)"
# cursor.execute(insert_sql, (1, "root1", 18))
# cursor.execute(insert_sql, (2, "root2", 18))
# cursor.execute(insert_sql, (3, "root3", 18))
# cursor.execute(insert_sql, (4, "root4", 18))
# cursor.execute(insert_sql, (5, "root5", 18))
# conn.commit()

# update_sql = "update sys_user set name=? where id=?"
# cursor.execute(update_sql,("test1",1))
# conn.commit()

# delete_sql = "DELETE FROM sys_user WHERE id=?"
# cursor.execute(delete_sql, (4,))
# conn.commit()

select_sql = "select * from sys_user"
cursor.execute(select_sql)
for row in cursor:
    print(row)